package com.company.poker.network;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.handler.codec.string.StringDecoder;
import org.jboss.netty.handler.codec.string.StringEncoder;
import org.jboss.netty.util.CharsetUtil;

import java.util.Set;

import static org.jboss.netty.channel.Channels.pipeline;


public class NetworkPipelineFactory implements ChannelPipelineFactory {

    protected SimpleChannelHandler handler;
    private Set<Channel> channels;

    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = pipeline();
        // Decoders
//        pipeline.addLast("frameDecoder", new FromByteToStringDecoder());
//        pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(1024));
        pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));

        // Encoder
        pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
        // and then business logic.
        pipeline.addLast("handler", handler);

        return pipeline;
    }

    public SimpleChannelHandler getHandler() {
        return handler;
    }

    public void setHandler(SimpleChannelHandler handler) {
        this.handler = handler;
    }
}
